/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef SHADERPROGRAMS_H
#define SHADERPROGRAMS_H

#include "defines.h"     // include this before anything else.
#ifdef SMASHMINER_CONFIG_USE_OPENGL_ES_2

#include <QtOpenGL/qglshaderprogram.h>

class spBase : public QGLShaderProgram
{
    Q_OBJECT

    public:
    spBase(QGLShader *, QGLShader *);
    ~spBase();

    /// Set the ''matrix'' attribute to shader program
    inline void setMatrix(QMatrix4x4 &m) {
        setUniformValue(matrixLoc, m);
    }

    /// Enable vertex array ''vertex''
    inline void enableVertexArray() {
        enableAttributeArray(vertexLoc);
    }

    /// Set array of vertex values
    inline void setVertexArray(GLfloat *v) {
        setAttributeArray(vertexLoc, v, 3);
    }

    /// Disable vertex array
    inline void disableVertexArray() {
        disableAttributeArray(vertexLoc);
    }

private:

    /// Attribute location for ''matrix'' attribute
    int matrixLoc;
    /// Attribute location for ''vertex'' attribute
    int vertexLoc;

};

//////////////////////////////////////////////////////////////////////////

class spTexture : public spBase
{
    Q_OBJECT

public:

    spTexture(QGLShader *, QGLShader *);

    /// Enable texture array
    inline void enableTextureArray() {
        enableAttributeArray(texCoordLoc);
    }

    inline void setTextureArray(GLfloat *t) {
        setAttributeArray(texCoordLoc, t, 2);
    }

    inline void disableTextureArray() {
        disableAttributeArray(texCoordLoc);
    }

private:

    /// Attribute location for ''texcoord'' attribute
    int texCoordLoc;
};

//////////////////////////////////////////////////////////////////////////

class spTextureEff3D : public spTexture
{
    Q_OBJECT

public:

    spTextureEff3D(QGLShader *, QGLShader *);

    inline void setBlackHoleData4(QVector4D &v) {
        setUniformValue(bhData4Loc, v);
    }

private:

    /// Attribute location for ''bhdata4'' attribute (black hole data)
    int bhData4Loc;
};

//////////////////////////////////////////////////////////////////////////

class spBackGround : public spTexture
{
    Q_OBJECT

public:

    spBackGround(QGLShader *, QGLShader *);

};

//////////////////////////////////////////////////////////////////////////

class spBackGroundEff2D : public spBackGround 
{
    Q_OBJECT

public:

    spBackGroundEff2D(QGLShader *, QGLShader *);

    inline void setBombData(QVector4D &v) {
        setUniformValue(bombDataLoc, v);
    }

    inline void setBlackHoleData3(QVector3D &v) {
        setUniformValue(bhData3Loc, v);
    }

private:

    /// Attribute location for ''bombdata'' attribute (black hole data)
    int bombDataLoc;
    /// Attribute location for ''bhdata3'' attribute (black hole data)
    int bhData3Loc;
};

//////////////////////////////////////////////////////////////////////////

class spConstantMaterial : public spBase
{
    Q_OBJECT

public:

    spConstantMaterial(QGLShader *, QGLShader *);

    inline void setLightMaterialAmbient(QVector4D &v) {
        setUniformValue(lmAmbientLoc, v);
    }

    inline void setLightMaterialDiffuse(QVector4D &v) {
        setUniformValue(lmDiffuseLoc, v);
    }

    inline void setLightDirection(QVector3D &v) {
        setUniformValue(lightDirLoc, v);
    }

    inline void enableNormalArray() {
        enableAttributeArray(normalLoc);
    }

    inline void setNormalArray(GLfloat *v) {
        setAttributeArray(normalLoc, v, 3);
    }

    inline void disableNormalArray() {
        disableAttributeArray(normalLoc);
    }

private:

    int lmAmbientLoc;
    int lmDiffuseLoc;
    int lightDirLoc;
    int normalLoc;
};

//////////////////////////////////////////////////////////////////////////

class spConstantMaterialEff3D : public spConstantMaterial 
{
    Q_OBJECT

public:

    spConstantMaterialEff3D(QGLShader *, QGLShader *);

    inline void setBlackHoleData4(QVector4D &v) {
        setUniformValue(bhData4Loc, v);
    }

private:

    /// Attribute location for ''bhdata4'' attribute (black hole data)
    int bhData4Loc;
};

//////////////////////////////////////////////////////////////////////////

class spVariableMaterial : public spConstantMaterial
{
    Q_OBJECT

public:

    spVariableMaterial(QGLShader *, QGLShader *);

    inline void enableMaterialArray() {
        enableAttributeArray(materialLoc);
    }

    inline void setMaterialArray(GLfloat *v) {
        setAttributeArray(materialLoc, v, 3);
    }

    inline void disableMaterialArray() {
        disableAttributeArray(materialLoc);
    }

private:

    /// Attribute location for ''material'' attribute (variable material data, colour value for 
    /// each vertex point) 
    int materialLoc;
};

//////////////////////////////////////////////////////////////////////////

class spVariableMaterialEff3D : public spVariableMaterial 
{
    Q_OBJECT

public:

    spVariableMaterialEff3D(QGLShader *, QGLShader *);

    inline void setBlackHoleData4(QVector4D &v) {
        setUniformValue(bhData4Loc, v);
    }

private:

    /// Attribute location for ''bhdata4'' attribute (black hole data)
    int bhData4Loc;
};

//////////////////////////////////////////////////////////////////////////

class spParticles : public spBase
{
    Q_OBJECT

public:

    spParticles(QGLShader *, QGLShader *);

    inline void enablePDataArray() {
        enableAttributeArray(pdataLoc);
    }

    inline void setPDataArray(GLfloat *v) {
        setAttributeArray(pdataLoc, v, 3);
    }

    inline void disablePDataArray() {
        disableAttributeArray(pdataLoc);
    }

private:

    /// Attribute location for ''pdata'' attribute (particle data)
    int pdataLoc;
};

//////////////////////////////////////////////////////////////////////////

class spParticlesEff2D : public spParticles 
{
    Q_OBJECT

public:

    spParticlesEff2D(QGLShader *, QGLShader *);

    inline void setBlackHoleData3(QVector3D &v) {
        setUniformValue(bhData3Loc, v);
    }

private:

    /// Attribute location for ''bhdata3'' attribute (black hole data)
    int bhData3Loc;
};

//////////////////////////////////////////////////////////////////////////

class spControlGauges : public spBase
{
    Q_OBJECT

public:

    spControlGauges(QGLShader *, QGLShader *);

};

//////////////////////////////////////////////////////////////////////////

class spRewindGauge : public spBase
{
    Q_OBJECT

public:

    spRewindGauge(QGLShader *, QGLShader *);
};

#endif  // SMASHMINER_CONFIG_USE_OPENGL_ES_2
#endif  // SHADERPROGRAMS_H
